<?php 
if(!defined('HOST'))die('not access');
?>
<script >
$(document).ready(function(){
	var fqarr = {},isgl=0,isup=0,isxz=0,rand='{rand}',fqid=0,folderid=0,officelx=',docx,doc,xlsx,xls,ppt,pptx,';
	
	var at = $('#optionview_{rand}').bootstable({
		url:'',autoLoad:false,
		columns:[{
			text:'分区名称',dataIndex:'name',align:'left',xtype:'treecolumn',width:'74%'
		},{
			text:'文件数',dataIndex:'fileshu',width:'25%'
		}],
		load:function(d){
		},
		itemdblclick:function(d){
			c.openfenqu(d);
		},
		itemclick:function(d){
			
		}
	});
	
	var a = $('#viewlist_{rand}').bootstable({
		celleditor:true,checked:true,url:js.apiurl('word','data'),fanye:true,
		method:'get',cellurl:'index.php?m=index&a=savecell',params:{key:jm.base64encode($('#mainsou').val())},
		tablename:'4',
		bodyStyle:'height:'+(viewheight-115)+'px;overflow:auto',
		columns:[{
			text:'',dataIndex:'fileext',renderer:function(v,d){
				if(!isempt(d.thumbpath))return '<img src="'+js.fileuppath(d.thumbpath)+'" onclick="js.viewimg(this)" width="24" height="24">';
				if(d.type=='0'){
					var lxs = js.filelxext(v);
					return '<img src="'+FILE_URL+'images/fileicons/'+lxs+'.gif"  height="24">';
				}else{
					return '<img src="images/folder.png" height="24">';
				}
			}
		},{
			text:'名称',dataIndex:'filename',sortable:true,editor:true,align:'left',editorbefore:function(d){
				if(isgl=='0'){
					return false;
				}else{
					return true;
				}
			}
		},{
			text:'大小',dataIndex:'filesize',sortable:true,renderer:function(v,d){
				if(d.type=='1'){
					v='&nbsp;';
					if(d.downshu>0)v='<font color=#aaaaaa>有子目录</font>';
				}
				if(d.type=='0')v=js.formatsize(v);
				return v;
			}
		},{
			text:'创建者',dataIndex:'optname'
		},{
			text:'最后修改',dataIndex:'optdt',sortable:true,renderer:function(v,d){
				if(d.type=='1')v='&nbsp;';
				return v;
			}
		},{
			text:'共享给',dataIndex:'shatename'
		},{
			text:'排序号',dataIndex:'sort',editor:true,sortable:true,editorbefore:function(d){
				if(isgl=='0'){
					return false;
				}else{
					return true;
				}
			}
		},{
			text:'',dataIndex:'opt',align:'left',renderer:function(v,d,oi){
				if(d.ishui=='1')return '已删';
				if(d.type=='1'){
					return '<a class="zhu" onclick="obj{rand}.openfolder('+d.fqid+','+d.id+')">打开</a>';
				}else{
					var s = '<a class="zhu" onclick="js.fileopt(\''+d.filenum+'\',0)">预览</a>';
					if(officelx.indexOf(','+d.fileext+',')>-1 && isgl==1)s+='&nbsp;<a class="zhu" onclick="js.fileopt(\''+d.filenum+'\',2)">编辑</a>';
					if(isxz==1)s+='&nbsp;<a class="zhu" onclick="js.fileopt(\''+d.filenum+'\',1)"><i class="icon-arrow-down"></i></a>';
					return s;
				}
			}
		}],
		load:function(d){
			
		},
		loadbefore:function(d){
			c.loadbefore(d);
		},
		itemdblclick:function(d){
			if(d.type=='1')c.openfolder(d.fqid,d.id);
		}
	});
	
	
	var c = {
		init:function(){
			this.treelist('分区列表');
		},
		booes:false,
		clickwin:function(){
			
		},
		relad:function(){
			a.reload();
		},
		treelist:function(tit,w){
			$('#optionview_{rand}').css('height',''+(viewheight-25)+'px');
		},
		loadbefore:function(d){
			this.showpatharr(d.patharr);
			if(this.booes)return;
			this.booes = true;
			at.loadData({
				rows:d.crows,
				totalCount:1,
			});
		},
		openfenqu:function(d){
			isgl = 0;isup = 0;
			this.btnbool(true);
			this.openfolder(d.id,0);
		},
		openfolder:function(id1,id2){
			fqid = id1;
			folderid = id2;
			a.setparams({fqid:id1,folderid:id2,key:''}, true);
		},
		fqarr:false,
		showpatharr:function(da){
			var str='',i,d1=da[0];
			this.fqarr = d1;
			for(i=0;i<da.length;i++){
				if(i>0)str+=' <font color="#cccccc">/</font>';
				str+=' <a class="zhu"  onclick="obj'+rand+'.openfolder('+da[i].fqid+','+da[i].folderid+')">'+da[i].name+'</a>';
			}
			isgl = d1.isgl;
			isup = d1.isup;
			isxz = d1.isxz;
			var zts = '',ysz='';
			if(isgl==0){
				if(isup==1){
					zts='仅上传';
					ysz= '#0099CC';
				}else{
					zts='只读';
					ysz= '#aaaaaa';
				}
			}else{
				if(isup==1){
					zts='可管理可上传';
					ysz= 'green';
				}else{
					zts='仅管理';
					ysz= '#CC6666';
				}
			}
			if(isup==1)this.btnbool(false);
			get('delbtn{rand}').disabled = (isgl==0);
			get('optbtn{rand}').disabled = (isgl==0);
			var bo = (isgl==1);
			a.setCans({checked:bo,celleditor:bo});
			$('#toolbarcenter{rand}').html('<span class="badge" style="background:'+ysz+'">'+zts+'</span>'+str);
		},
		btnbool:function(bo){
			get('upbtn{rand}').disabled = bo;
			get('folderbtn{rand}').disabled = bo;
			
		},
		createfolder:function(){
			js.prompt('输入文件夹名称',function(jg,txt){
				if(jg=='yes' && txt){
					js.loading('创建中...');
					js.ajax({
						url:js.apiurl('word','createfolder'),
						data:{fqid:fqid,folderid:folderid,name:txt},
						type:'post',
						success:function(){
							js.msgok('创建成功');
							a.reload();
						}
					});
				}
			},'创建文件夹');
		},
		uploadfile:function(){
			js.showuploadfile('上传到['+this.fqarr['name']+']分区', this.fqarr['uptype'], function(fnum){
				if(!fnum)return;
				c.saveuploadfile(fnum);
			});
		},
		saveuploadfile:function(fnum){
			js.loading('添加中...');
			js.ajax({
				url:js.apiurl('word','savefile'),
				data:{fnum:fnum,fqid:fqid,folderid:folderid},
				type:'post',
				dataType:'json',
				success:function(ret){
					if(ret.success){
						js.msgok(ret.data.msg);
						a.reload();
					}else{
						js.msgerror(ret.msg);
					}
				}
			});
		},
		delchu:function(){
			var sid = a.getchecked();
			if(!sid){js.msgerror('复选框没有选中');return;}
			a.del({
				msg:'确定要删除选中文件/文件夹吗？',
				url:js.apiurl('word','delword',{fqid:fqid}),
				checked:true
			});
		},
		optbtn:function(d){
			var xid = a.getchecked();
			if(!xid){js.msgerror('复选框没有选中');return;}
			if(d.lx==0){
				js.changeuser('', 'deptusercheck', '请选择人员',{
					onselect:function(sna,sid){
						c.saveshate(sna,sid,xid,d.name);
					}
				});
			}else{
				c.saveshate('','',xid,d.name);
			}
		},
		saveshate:function(sna,sid,xid,ns){
			js.loading(''+ns+'中...');
			js.ajax({
				url:js.apiurl('word','saveshate'),
				data:{sna:sna,sid:sid,xid:xid,fqid:fqid},
				type:'post',
				success:function(){
					js.msgok(''+ns+'成功');
					a.reload();
				}
			});
		},
		search:function(){
			a.setparams({key:jm.base64encode($('#mainsou').val())}, true);
		}
	}
	
	c.init();
	js.initbtn(c);
	obj{rand} = c;
	mainword  = c;
	
	$('#optbtn{rand}').rockmenu({
		width:120,top:35,
		data:[{name:'共享',lx:0},{name:'取消共享',lx:1}],
		itemsclick:function(d){
			c.optbtn(d);
		}
	});
	
	a.settishi('管理请先双击左边的分区');
});

</script>

<table width="100%">
<tr valign="top">
<td width="220">
	<div style="border:1px #cccccc solid;width:220px">
	  <div id="optionview_{rand}" style="height:400px;overflow:auto;"></div>
	</div>  
</td>
<td width="10"></td>
<td>	
	
	<div id="buttonlist{rand}">

	<table width="100%" style="background:none">
		<tr>
		<td >
			<button class="webbtn" id="upbtn{rand}" clickevt="uploadfile" disabled type="button"><i class="icon-cloud-upload"></i> 上传文件</button>
		</td>
		<td  width="90%" style="padding-left:10px"><div id="toolbarcenter{rand}">所有分区</div></td>
		<td  style="padding-right:10px">
			
		</td>
		<td align="right" nowrap>
			<button class="webbtn webbtn-white" id="optbtn{rand}" disabled type="button">选中操作 <i class="icon-angle-down"></i></button>&nbsp; 
			<button class="webbtn webbtn-white" id="folderbtn{rand}" clickevt="createfolder" disabled type="button"><i class="icon-folder-close-alt"></i> 创建文件夹</button>&nbsp; 
			<button class="webbtn webbtn-red" id="delbtn{rand}" clickevt="delchu" disabled type="button"><i class="icon-trash"></i> 删除</button>
			<!--
			&nbsp; <button class="webbtn" title="列表" type="button"><i class="icon-align-justify"></i></button>&nbsp; 
			<button class="webbtn" title="缩略图" type="button"><i class="icon-th"></i></button>-->
		</td>
	</tr>
	</table>
	</div>

	<div class="blank10"></div>

	<div id="viewlist_{rand}"></div>
	
</td>
</tr>
</table>


